package dao

import javax.inject.Inject
import models.Tables._
import play.api.db.slick.{DatabaseConfigProvider, HasDatabaseConfigProvider}
import slick.jdbc.JdbcProfile

import scala.concurrent.{ExecutionContext, Future}

class MtgenomeDao@Inject()(protected val dbConfigProvider: DatabaseConfigProvider)(implicit exec:ExecutionContext)
  extends HasDatabaseConfigProvider[JdbcProfile]  {

  import profile.api._

  def insert(row:Seq[MtgenomeRow]) : Future[Unit] = {
    db.run(Mtgenome ++= row).map(_=>())
  }

  def getAll : Future[Seq[MtgenomeRow]] = {
    db.run(Mtgenome.result)
  }

  def getById(id:Int) : Future[MtgenomeRow] = {
    db.run(Mtgenome.filter(_.id === id).result.head)
  }

  def getByMtId(id:String) : Future[Seq[MtgenomeRow]] = {
    db.run(Mtgenome.filter(_.mtid === id).result)
  }

  def getByName(name:String) : Future[MtgenomeRow] = {
    db.run(Mtgenome.filter(_.name.like(name+"%")).result.head)
  }

  def getIdsByNames(names:Seq[String]) : Future[Seq[Int]] = {
    db.run(Mtgenome.filter(_.name.inSetBind(names)).map(_.id).result)
  }


}
